import requests
import json

kw = input("请输入关键字：")
num = input("您想要几个：")
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
}
data = {
    'cname': '',
    'pid': '',
    'keyword': kw,
    'pageIndex': '1',
    'pageSize': num
}
url = 'http://www.kfc.com.cn/kfccda/ashx/GetStoreList.ashx?op=keyword'
response = requests.post(url,data,headers)
result = response.json()

# 写入TXT文档
# result = result["Table1"]
# for each in result:
#     name = "名字：" + each['storeName']
#     address = "    地址：" + each['addressDetail']
#     pro =  "    提供: " + each['pro']
#     information = name + address + pro
#     with open('kfc.txt','a',encoding='utf-8') as f:
#         f.write(information+'\n')


# 写入json文件
# fp = open('./kfc.json','w',encoding='utf-8')
# json.dump(result,fp=fp,ensure_ascii=False)
